layui.use(['form','layer','jquery','carousel'], function () {
    var $ = layui.jquery,
        form = layui.form,
        carousel = layui.carousel;
    var imgH = document.getElementById('login_carousel').querySelector('.img-item').offsetHeight;
    document.getElementById('imgH').style.height = imgH+'px';

    window.onresize = function () {
        var imgH = document.getElementById('login_carousel').querySelector('.img-item').offsetHeight;
        document.getElementById('imgH').style.height = imgH+'px';
    };
    /**背景图片轮播*/
    carousel.render({
        elem: '#login_carousel',
        width: '100%' //设置容器宽度
        ,arrow: 'always' // 悬停显示箭头
        ,indicator: 'inside'
        ,height: 'auto'


    });
//监听轮播切换事件
    carousel.on('change(login_carousel)', function(obj){ //test1来源于对应HTML容器的 lay-filter="test1" 属性值
        console.log(obj.index); //当前条目的索引
        console.log(obj.prevIndex); //上一个条目的索引
        console.log(obj.item); //当前条目的元素对象
    });
    /**重新生成验证码*/
    function reqCaptcha() {
        var url = "/captcha?nocache=" + new Date().getTime()
        $('.code img').attr("src",url)
    }
    /**点击验证码重新生成*/
    $('.code img').on('click', function () {
        reqCaptcha();
    });
    form.on('submit(login)', function(data) {
        var loadIndex = layer.load(2, {
            shade: [0.3, '#333']
        });
        if($('form').find('input[type="checkbox"]')[0].checked){
            data.field.rememberMe = true;
        }else{
            data.field.rememberMe = false;
        }

        $.post(data.form.action, data.field, function(res) {
            layer.close(loadIndex);
            if(res.success){
                location.href=res.data.url;
            }else{
                layer.msg(res.message);
                reqCaptcha();
            }
        });
        return false;
    });

    // layer.alert('账号:user_system/123456 用户管理员<br>账号:user_readonly/123456 只读用户<br>原admin账号暂时回收');
});